package de.baumann.browser.views.dialog

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.os.Handler
import android.os.Message
import android.view.Gravity
import de.baumann.browser.R
import de.baumann.browser.activitys.GuideActivity
import de.baumann.browser.activitys.MainActivity
import de.baumann.browser.units.TimerUnit
import de.baumann.browser.utils.TimeUtil
import de.baumann.browser.utils.getBoolean
import kotlinx.android.synthetic.main.dialog_not_enough_fene.*
import kotlin.concurrent.timer

class FeneNotEnoughDialog(context: Context) : BaseDialog(context) {


    override fun laoutId(): Int {
        return R.layout.dialog_not_enough_fene
    }


    private var time = 10
    private var handler: Handler = object : Handler() {
        override fun handleMessage(msg: Message?) {
            super.handleMessage(msg)
            if (time > 0) {
                btnrym.isClickable = false
                time--
                btnrym.text = "仍然购买(${time}s)"
                sendEmptyMessageDelayed(0, 1000)
            } else {
                btnrym.isClickable = true
                btnrym.text = "仍然购买"
            }
        }
    }

    @SuppressLint("SetTextI18n")
    override fun initView() {

        bxml.setOnClickListener {
            dismiss()
        }

        btnrym.setOnClickListener {
            dismiss()
        }
    }

    fun a(residue_part_num: String) {
        handler.sendEmptyMessageDelayed(0, 1000)
        syfe.text = "还剩${residue_part_num}份"
    }

    override fun gravity(): Int {
        return Gravity.BOTTOM
    }

}